// -----------------------------
// Author: 		Dhaenens Gert	
// Creation: 	10/18/2014 12:59:59 AM				
// -----------------------------

#include "Mesh.h"

#include "RenderManager.h"

Mesh::Mesh(RenderManager* lpRenderManager)
	: m_lpRenderManager(lpRenderManager)
	, m_lpVertexBuffer(nullptr)
	, m_lpIndexBuffer(nullptr)
{
}

Mesh::~Mesh()
{
	NullRelease(&m_lpVertexBuffer);
	NullRelease(&m_lpIndexBuffer);
}

void Mesh::SetVertices(const VertexList& vertices)
{
	NullRelease(&m_lpVertexBuffer);
	m_lpVertexBuffer = IBuffer::Create(m_lpRenderManager->GetDevice(), BufferType::Vertex, Usage::Default, 0, sizeof(Vertex), (UInt32) vertices.size(), vertices.data());
	m_Vertices = vertices;
}
void Mesh::SetIndices(const IndexList& indices)
{
	NullRelease(&m_lpIndexBuffer);
	m_lpIndexBuffer = IBuffer::Create(m_lpRenderManager->GetDevice(), BufferType::Index, Usage::Default, 0, sizeof(Index), (UInt32) indices.size(), indices.data());
	m_Indices = indices;
}

Mesh::VertexList Mesh::GetVertices() const
{
	return m_Vertices;
}
Mesh::IndexList Mesh::GetIndices() const
{
	return m_Indices;
}

IBuffer* Mesh::GetVertexBuffer() const
{
	return m_lpVertexBuffer;
}
IBuffer* Mesh::GetIndexBuffer() const
{
	return m_lpIndexBuffer;
}